SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

Alter  trigger tfb_fixastmodify_ai on dbo.tfb_fixastmodify 
after insert 
as   
begin   
 if @@rowcount<>1 return
 set nocount on
 declare @ifaadjid integer;   
 declare @ifixedassetid integer;
 declare @imodtypeid   int;

 select @ifaadjid = faadjid,
        @ifixedassetid = fixedassetid,
        @imodtypeid = modtypeid
 from inserted;
 
 insert into tfb_oldfixedassets(asssetchangeid,fixedassetid,deproption,   
                               planusemonth,sumusedmonth,planworkvalue,   
                               sumworkedvalue,rawamt,price,quantity,sumdepramt,remainamt,   
                               remainrate,monthdepramt,monthdeprrate,statusid,   
                               deprmethodid,astsubid,dprsubid,workunit,location)   
 select @ifaadjid as asssetchangeid,fixedassetid,deproption,planusemonth,   
                            sumusedmonth,planworkvalue,sumworkedvalue,   
                            rawamt,price,quantity,sumdepramt,remainamt,remainrate,   
                            monthdepramt,monthdeprrate,statusid,deprmethodid,astsubid,dprsubid,workunit,location 
 from tfb_fixedassets where fixedassetid=@ifixedassetid;    
 
 if (@imodtypeid=2)    
 begin   
   update tfb_fixastdept set used=0 where fixedassetid=@ifixedassetid and used=1;   
 end    
end

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

